package com.lanf.crm.web.controller.admin;


import com.lanf.crm.dto.LayuiResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/img")
public class ImgUpController {
    //上传图片的配置，用的是commons工具，文件存储路径为项目以外
    @PostMapping("/imgUpLoad")
    public LayuiResult<String> imgUpLoad(@RequestParam(value = "file", required = false)
                                      MultipartFile file) {
        String rootPath = "D:/site_file/images/";
        String path = rootPath + file.getOriginalFilename();
        try {
            file.transferTo(new File(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        LayuiResult<String> result=new
                LayuiResult<>();
        result.setCode("0");
        result.setData("/images/" + file.getOriginalFilename());
        result.setMessage("文件上传成功");
       return result;
    }
}